package com.emperor.util;

import org.apache.log4j.Logger;
import org.hibernate.*;
import org.hibernate.cfg.*;

import com.emperor.core.app.AppConstant;

public class HibernateUtil {
	private static final SessionFactory sessionFactory;
	
	static {
		try {
			// Create the SessionFactory from hibernate.cfg.xml
			sessionFactory = new Configuration().configure(AppConstant.HIBERNATE_CONFIG)
					.buildSessionFactory();
		} catch (Throwable ex) {
			Logger log = Logger.getLogger(HibernateUtil.class);
			log.error("Initial SessionFactory creation failed.", ex);
			throw new ExceptionInInitializerError(ex);
		}
	}

	public static SessionFactory getSessionFactory() {
		return sessionFactory;
	}
}